package com.naiterui.ehp.bs.doctor.dao.impl;

import com.naiterui.ehp.bs.doctor.dao.IDrNoticeInfoDao;
import com.naiterui.ehp.bs.doctor.domain.DrNoticeInfo;
import com.naiterui.ehp.bs.doctor.repository.IDrNoticeInfoRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Component
public class AdDrNoticeInfoDaoImpl implements IDrNoticeInfoDao {

    @Autowired
    private IDrNoticeInfoRepository drNoticeInfoRepository;

    @Override
    public void save(DrNoticeInfo noticeInfo) {
        drNoticeInfoRepository.save(noticeInfo);
    }

    @Override
    public Map<Long, DrNoticeInfo> getDrNoticeInfoByList(List<Long> idList) {
        Map<Long, DrNoticeInfo> map = new HashMap<>();
        if (idList != null && !idList.isEmpty()) {
            Iterable<DrNoticeInfo> list = drNoticeInfoRepository.findAllById(idList);
            if (list != null ) {
                for (DrNoticeInfo info : list) {
                    map.put(info.getId(), info);
                }
            }
        }
        return map;
    }

    @Override
    public DrNoticeInfo getNewDoctorNotice(Long doctorId, Integer msgScene) {
        List<DrNoticeInfo> list = drNoticeInfoRepository.findByDoctorIdAndMsgScene(doctorId, msgScene);
        if (list != null && !list.isEmpty()) {
            return list.get(0);
        }
        return null;
    }

}
